using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Zonas", new WebServiceHostFactory(), typeof(ZonasService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class ZonasService : BaseService
    {

        [WebInvoke(UriTemplate = "Create", Method = "POST")]
        public bool Create(Zonas Zona)
        {
            Provider.AddToZonas(Zona);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetAll", Method = "POST")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Zonas.ToList());
        }

        [WebInvoke(UriTemplate = "GetById", Method = "POST")]
        public Zonas GetById(int Id)
        {
            return Provider.Zonas.First(i => i.IdZona == Id);
        }

        [WebInvoke(UriTemplate = "Update", Method = "POST")]
        public bool Update(Zonas Zona)
        {
            Zonas miZona = Provider.Zonas.Where(t => t.IdZona == Zona.IdZona).First();
            miZona.Copy(Zona);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "Delete", Method = "POST")]
        public bool Delete(int IdZona)
        {
            Provider.Zonas.DeleteObject(Provider.Zonas.Where(t => t.IdZona == IdZona).First());
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "GetByDepartamento", Method = "POST")]
        public ArrayList GetByDepartamento(int IdDepartamento)
        {
            return new ArrayList(Provider.Zonas.Where(z => z.IdDepartamento == IdDepartamento).ToList());
        }
    }
}